package com.imessage.type;


import com.fasterxml.jackson.annotation.JsonValue;
import io.ebean.annotation.DbEnumValue;

import java.util.Objects;

public enum BusinessTaskState implements EnumMessage {

    init("-1", "初始", "init", ""),
    finish("1", "完成", "finish", ""),
    wait("2", "等待", "stop", ""),
    run("3", "运行", "run", "");


    String code;
    String display;
    String name;
    String value;

    private BusinessTaskState(String code, String display, String name, String value) {
        this.code = code;
        this.display = display;
        this.name = name;
        this.value = value;
    }

    //获取枚举实例
    public static BusinessTaskState fromValue(String code) {
        for (BusinessTaskState statusEnum : BusinessTaskState.values()) {
            if (Objects.equals(code, statusEnum.getCode())) {
                return statusEnum;
            }
        }
        return BusinessTaskState.wait;
    }

    //获取枚举实例
    public static BusinessTaskState toValue(String display) {
        for (BusinessTaskState statusEnum : BusinessTaskState.values()) {
            if (Objects.equals(display, statusEnum.getDisplay())) {
                return statusEnum;
            }
        }
        return BusinessTaskState.wait;
    }


    @DbEnumValue
    @Override
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    @JsonValue
    public String getDisplay() {
        return display;
    }

    public void setDisplay(String display) {
        this.display = display;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return display;
    }
}
